﻿using UnityEngine;
using System.Collections;

public class PlayerAnimatorAttack : MonoBehaviour {

    private Animator animator;
    private bool AXK = true;
    private bool BXK = true;
    private bool isCanUseAttackB;
    void Awake()
    {
        animator=GetComponent<Animator>();
    }

	// Use this for initialization
	void Start () {
        // 事件监听方法
        PlayerAnimatorAttack awss = this;
        EventDelegate NormalAttackEvent = new EventDelegate(awss, "OnNormalAttackClick");
        GameObject.Find("NormalAttack").GetComponent<UIButton>().onClick.Add(NormalAttackEvent);

        NormalAttackEvent = new EventDelegate(this, "OnRangeAttackClick");
        GameObject.Find("RangeAttack").GetComponent<UIButton>().onClick.Add(NormalAttackEvent);

        NormalAttackEvent = new EventDelegate(this, "OnGunAttackClick");
        GameObject.Find("GunAttack").GetComponent<UIButton>().onClick.Add(NormalAttackEvent);

	}
	
	// Update is called once per frame
	void Update () {
	
	}

    // 普通攻击
    public void OnNormalAttackClick()
    {
        /*       if (!AXK)
               {

                   if (!animator.GetCurrentAnimatorStateInfo(0).IsName("PlayerAttackA"))
                   {

                       AXK = true;
                   }
               }

               if (AXK)
               {
               animator.SetTrigger("AttackA");
               AXK = false;
               }
               else
               {
                   animator.SetTrigger("AttackB");
                   AXK = true;
               }
       */

        if (gameObject)
        {
            if (animator.GetCurrentAnimatorStateInfo(0).IsName("PlayerAttackA") && isCanUseAttackB)
            {
                animator.SetTrigger("AttackB");
            }
            else
            {
                if ((animator.GetCurrentAnimatorStateInfo(0).IsName("PlayerStand") || animator.GetCurrentAnimatorStateInfo(0).IsName("PlayerRun")))
                {
                    animator.SetTrigger("AttackA");
                }
            }

        }
    }
    // 群体攻击
    public void OnRangeAttackClick()
    {
        animator.SetTrigger("AttackRange");
        
    }
    // 枪支实现攻击
    public void OnGunAttackClick()
    {
        animator.SetTrigger("AttackGun");
    }

    public void AttackBEvent01()
    {
        isCanUseAttackB = true;
    }

    public void AttackBEvent02()
    {
        isCanUseAttackB = false;
    }


}
